    //约课顾问默认配置
    ykConfig = [
        {panelId : 1,name : "提醒列表",state : 1,method : "trackRemindByBccId(1,'提醒列表')"},
        {panelId : 2,name : "潜在客户",state : 1, method : "mainTipPotentialByBccId(2,'潜在客户')"},
        {panelId : 3,name : "已约未上",state : 1,method : "demoMissedListByBccId(3,'已约未上')"},
        {panelId : 4,name : "Demo未完成",state : 1, method : "unfinishDemoCourseByBccId(4,'Demo未完成')"},
        {panelId : 5,name : "Demo已完成",state : 1,method : "demoFinishedListByBccId(5,'Demo已完成')"}
    ];

    //课程顾问默认配置
    ccConfig = [
        {panelId : 1,name : "提醒列表", state : 1, method : "trackRemindByccId(1,'提醒列表')"},
        {panelId : 2,name : "订单到期列表",state : 1, method : "stuOrderInfoByCC(2,'订单到期列表')"},
        {panelId : 3,name : "已约未上",state : 1,method : "demoMissedListByCC(3,'已约未上')"},
        {panelId : 11,name : "待约家长会",state : 1,method : "bookingLctClass(11,'待约家长会')"},
        {panelId : 4,name : "潜在客户", state : 1,method : "mainTipPotentialByCCId(4,'潜在客户')"},
        {panelId : 5,name : "已上可跟进",state : 1,method : "appointedStudent(5,'已上可跟进')"},
        {panelId : 6,name : "Ref Leads",state : 1,method : "mainTipRelLeadsByCC(6,'Ref Leads')"},
        {panelId : 7,name : "新学员",state : 1,method : "mainTipNewStudentByCCId(7,'新学员')"},
        {panelId : 8,name : "oc调查问卷",state : 1,method : "ocInfoByCC(8,'oc调查问卷')"},
        {panelId : 9,name : "老师投诉学员",state : 1,method : "teacherRank(9,'老师投诉学员')"},
        {panelId : 10,name : "近月旷课学员",state : 1,method : "abnormalunFinishLessons(10,'近30天旷课5次以上跟进')"},
        {panelId : 12,name : "未设置动态提醒的学员",state : 1,method : "noReminderTime(12,'未设置动态提醒的学员')"},
        {panelId : 13,name : "订单总课时少于40节",state : 1,method : "surplusClassLessNUm(13,'订单总课时少于40节')"},
        {panelId : 14,name : "老学员跟进",state : 1,method : "oldStuFollow(14,'老学员跟进')"},
        {panelId : 15,name : "自动约课失败记录",state : 1,method : "autoFailBooked(15,'自动约课失败记录')"},
        {panelId : 16,name : "上课态度三星以下",state : 1,method : "classAttitude(16,'上课态度三星以下')"},
        {panelId : 17,name : "周课程少于3节",state : 1,method : "classWeekInfo(17,'外教周课程少于3节')"},
        {panelId : 18,name : "当天课程(不含demo、家长会)",state : 1,method : "classBookedToday(18,'当天课程(不含demo、家长会)')"},
        {panelId : 19,name : "学员最近成绩变化",state : 1,method : "lastTwoScoreInfo(19,'学员最近成绩变化')"},
    ];

    //ssc 默认配置
    sscConfig = [
        {panelId : 1,name : "提醒列表", state : 1, method : "trackRemindBysscId(1,'提醒列表')"},
        {panelId : 3,name : "教材快学完列表",state : 1,method : "materialFinished(3,'教材快学完列表')"},
        {panelId : 9,name : "学员投诉",state : 1,method : "stuEvaluation(9,'学员投诉')"},
        {panelId : 6,name : "近月旷课学员",state : 1,method : "abnormalunFinishLessons(6,'近30天旷课3次以上跟进')"},
        {panelId : 15,name : "待约中教课学员",state : 1,method : "notBookedChineseCourse(15,'待约中教课学员')"},
        {panelId : 13,name : "钻石学员跟进",state : 1,method : "diamondFollow(13,'钻石学员跟进')"},
        {panelId : 14,name : "待批改试卷",state : 1,method : "correctedTestPaperList(14,'待批改试卷')"},
        {panelId : 11,name : "离职老师常用学员",state : 1,method : "leaveTeacherStu(11,'离职老师常用学员')"},
        {panelId : 16,name : "待提交阶段检测报告",state : 1,method : "ltNotFeedback(16,'待提交阶段检测报告')"},
        {panelId : 2,name : "订单到期列表",state : 1, method : "stuOrderInfoBySsc(2,'订单到期列表')"},
        {panelId : 4,name : "新学员跟进", state : 1,method : "ocNewStudent(4,'新学员跟进')"},
        {panelId : 5,name : "老学员跟进",state : 1,method : "oldStuFollow(5,'老学员跟进')"},
        {panelId : 7,name : "Inactive学员",state : 1,method : "inactiveLessons(7,'Inactive学员')"},
        {panelId : 8,name : "老师投诉学员",state : 1,method : "teacherRank(8,'老师投诉学员')"},
        {panelId : 10,name : "续费将启动学员",state : 1,method : "renewOrders(10,'续费将启动学员')"},
        {panelId : 12,name : "新生预防针调查问卷",state : 1,method : "newStuYfz(12,'新生预防针调查问卷')"},
        {panelId : 17,name : "自动约课失败记录",state : 1,method : "autoFailBooked(17,'自动约课失败记录')"},
        {panelId : 18,name : "上课态度三星以下",state : 1,method : "classAttitude(18,'上课态度三星以下')"},
        {panelId : 19,name : "周课程少于3节",state : 1,method : "classWeekInfo(19,'外教周课程少于3节')"},
        {panelId : 20,name : "不满足下次自动约课订单",state : 1,method : "surplusAutoOrder(20,'不满足下次自动约课订单')"},
        {panelId : 21,name : "学员最近成绩变化",state : 1,method : "lastTwoScoreInfo(21,'学员最近成绩变化')"},
    ];

    //管理员 默认配置
    adminConfig = [
        {panelId : 1,name : "待约中教课学员",state : 1,method : "notBookedChineseCourse(1,'待约中教课学员')"},
        {panelId : 2,name : "待提交阶段检测报告",state : 1,method : "ltNotFeedback(2,'待提交阶段检测报告')"},
        {panelId : 3,name : "老学员跟进",state : 1,method : "oldStuFollow(3,'老学员跟进')"},
        {panelId : 4,name : "近30天旷课3次以上跟进",state : 1,method : "absenteeismLessons(4,'近30天旷课3次以上跟进')"},
        {panelId : 5,name : "订单到期列表",state : 1, method : "stuOrderInfo(5,'订单到期列表')"},
        {panelId : 6,name : "Inactive学员",state : 1,method : "inactiveLessons(6,'Inactive学员')"},
        {panelId : 7,name : "潜在客户", state : 1,method : "potentialStu(7,'潜在客户')"},
        {panelId : 8,name : "提醒列表", state : 1, method : "trackRemind(8,'提醒列表')"},
    ];

    //查询当前用户 排序规则
    function selectSort (config){
        let configs = [];
        configs.push.apply(configs,config);
        let sortList = [];
        $.ajax({
            type : "POST", //提交方式
            url : "/YkNewMainCtl/selectSortByUser",//路径
            data :{},
             //数据，这里使用的是Json格式进行传输JSON.stringify(data),
            async: false,
            dataType:"json",
            contentType: "application/x-www-form-urlencoded",
            success: function (data) {
                let list = data.userPanelSortList;
                if(list.length >0) {
                    for (let i=0;i<list.length;i++){
                        if (list.length===0) {
                            break;
                        }
                        for (let j = 0; j < configs.length; j++) {
                            if (list[i].panelId === configs[j].panelId) {
                                //添加已保存的排序对象
                                configs[j].state=list[i].state;
                                sortList.push(configs[j]);
                                //删除已排序的对象
                                configs.splice(j,1);
                                list.splice(i,1);
                                --i;
                                break;
                            }
                        }
                    }
                    if (configs.length >0) {
                        //加载没有保存的面板
                        sortList.push.apply(sortList,configs);
                    }
                }else{
                  sortList =  configs;//没有排序规则 就选择默认排序规则
                }
             },
            error: function (err) {
                console.log(err);
            }
        });
        //console.log("面板排序数据：");
        //console.log(sortList);
         return sortList;
    }

    //传入排序规则，生成排序配置列表
    function pubSortList(configList){
        let config = configList;
        let html='<form class="layui-form" action=""><div class="modal_nestable">';
        html+='<ul class="list-unstyled list_nestable" id="nestable">';
        for(let i = 0;i<config.length;i++){
            html+='<li>';
            html+='<div style="margin-left: 10%">';
            html+='<i class="fa  fa-list-ul fa-lg" aria-hidden="true"></i>';
            html+='<span>'+config[i].name+'</span>';
            html+='</div>';
            html+='<div class="layui-form-item" style="margin-top: -45px;margin-left: 40%;">';
            html+='    <div class="layui-input-block">';
            if(config[i].state == 1){
                html+='<input type="checkbox" name="config" data-id="'+config[i].panelId+'" lay-skin="switch" lay-text="ON|OFF" checked>' ;
                html+='<div class="layui-unselect layui-form-switch layui-form-onswitch"  lay-skin="_switch"><em>ON</em><i></i></div>' ;
            }else{
                html+='<input type="checkbox" name="config" data-id="'+config[i].panelId+'" lay-skin="switch" lay-text="ON|OFF">' ;
                html+='<div class="layui-unselect layui-form-switch"  lay-skin="_switch"><em>OFF</em><i></i></div>' ;
            }
            html+=    '    </div>';
            html+=    '  </div>';
            html+=' </li>';
        }
        html+='    </ul>';
        html+='   </div>';
        html+='<div class="layui-form-item">' ;
        html+='<div class="layui-input-block" style="margin-top: 30px;margin-left: 85px;">' ;
        html+='  <button class="layui-btn" onclick="savconfig()" lay-filter="demo1">立即提交</button>' ;
        html+='   <button type="reset" onclick="restoreDefaultConfig()" class="layui-btn layui-btn-primary">恢复默认</button>' ;
        html+=' </div>' ;
        html+=' </div>' ;
        html+='</form>';

        //打开排序规则 列表弹窗
        layer.open({
            title : "排序设置",
            type: 1,
            area: ['400px', '80%'],
            shadeClose: false, //点击遮罩关闭
            scrollbar: false, // 父页面 滚动条 禁止
            content: html
        });
        //初始化  form 表单元素
        layui.use(['form', 'layedit', 'laydate'], function(){
             var  form = layui.form;
             form.render();
        });

        // 列表拖动
        $('#nestable').gridly({
            base: 60,
            gutter: 15, // 边距
            columns: 8,
        });
    }

    //保存用户排序规则
    function savconfig(){
       let dom = $("#nestable").find("li");
        let config = [];
       for(let i = 0;i<dom.length;i++){
           let obj = {};
            obj.panelId = $(dom[i]).find('input').attr("data-id");
            obj.sort = $(dom[i]).css("top").replace("px","");
            if($(dom[i]).find(".layui-form-switch").hasClass("layui-form-onswitch")){
                obj.state = 1;
            }else{
                obj.state = 0;
            }
            config.push(obj);
       }
        //提交排序设置 调用提交公共ajax
        publicAjax(config);
    }

    //恢复默认设置
    function restoreDefault(configList){
        let config = [];
        for(let i = 0 ;i<configList.length;i++){
            let obj = {};
            obj.panelId = configList[i].panelId;
            obj.sort = i+1;
            obj.state = 1;
            config.push(obj);
        }
        //提交排序设置 调用提交公共ajax
        publicAjax(config);
    }

    //提交配置公共方法
    function publicAjax(config){
        //提交配置
        $.ajax({
            type : "POST", //提交方式
            url : "/YkNewMainCtl/addUserSort",//路径
            data : JSON.stringify(config),//数据，这里使用的是Json格式进行传输JSON.stringify(data),
            dataType:"json",
            contentType: "application/json;charset=utf-8",
            success: function (data) {
                if(data.code >0) {
                    layer.msg("设置成功",{
                      offset:['50%'],
                      time: 2500 //2秒关闭（如果不配置，默认是3秒）
                    },function(){
                       window.location.reload();
                    });
                }else{
                  layer.msg("设置失败");
                }
             },
            error: function (err) {
                console.log(err);
            }
        })
    }

    //面板外层生成公共  拼接方法
    function pubHtml(id,bg,tableName,addDom,addDom2){
        let html = '<div class="col-lg-6 col-md-12 col-sm-12 col-xs-12 main-box">';
            html +='    <div class="main-item">';
            html +='        <div class="title title_bg'+bg+'">';
            html +='            <div class="pull-left"><img src="../static/img/tixing.png" /><span>'+tableName+'</span></div>';
            html +='            <div class="pull-right">';
            html +=addDom;
            // html +='                <i class="fa fa-refresh refresh"></i>' ;
            html +='                <img src="../static/img/close.png" class="close_icon" />' ;
            html +='           </div>';
            html +=addDom2;
            html +='        </div>';
            html +='        <div class="content">' ;
            html +='            <div class="layui-col-md14" style="margin-top: -10px">';
            html +='                 <table class="layui-hide" id="'+id+'"></table>';
            html +='             </div>';
            html +='        </div>';
            html +='    </div>';
            html +='</div>';
        $(".gridly").append(html);
    }


    /**
     * 教师信息卡片弹窗
     * @param teacherId 老师id(personId)
     * @param url
     */
    function teacherInfo(teacherId){
       var url = "";
        if($("#url").length >0){
            url = $("#url").val()+"/admin/person_getTeacherEvaluation.action?person.id="+teacherId;
        }
        layer.open({
            type: 2,
            title: false,
            closeBtn: 1, //显示关闭按钮
            shade: [0.5],
            area: ['60%', '60%'],
            //offset: 'rb', //右下角弹出
            // time: 2000, //2秒后自动关闭
            anim: 2,
            content: [url, 'yes'], //iframe的url，no代表不显示滚动条
        });
    }

    /**
 * 学员基本信息卡片弹窗
  * @param personId  学员id
 */
function publishStuDynamic(personId,sscCheck){
        if(personId==null || personId == ''){
            layer.msg("参数错误");
            return;
        }
        var url = '/student/info?personId='+personId;
        if(sscCheck != null && sscCheck != ''){
            url+='&sscCheck='+sscCheck
        }
        layer.open({
                id: 'insert-form',
                type: 2,
                title: "",
                closeBtn: 1, //显示关闭按钮
                shade: [0.5],
                area: ['80%', '98%'],
                // offset: 'rb', //右下角弹出
                // time: 2000, //2秒后自动关闭
                maxmin: true, //开启最大化最小化按钮
                anim: 2,
                content: [url, 'yes'], //iframe的url，no代表不显示滚动条
                end: function (index, layer) { //此处用于演示
                    // var isVoidFresh = sessionStorage.getItem('isVoidFresh');
                    if(sscCheck === "s1" || sscCheck === "c1"){
                        // sessionStorage.removeItem('isVoidFresh');
                        reloadAbnormalunFinishLessons(); //关闭弹出框之后自动刷新父页面（未正常上课面板 ）
                    }else if(sscCheck === 2){
                        // sessionStorage.removeItem('isVoidFresh');
                        reloadInactiveLessons(); //关闭弹出框之后自动刷新父页面 inactive面板
                    }
                }
        });
    }





